package com.example.petproject.service.impl;

import com.example.petproject.entity.vo.CategoryListVO;
import com.example.petproject.mapper.PmsProductCategoryMapper;
import com.example.petproject.service.PmsProductCategoryService;
import com.example.petproject.service.third.ali.AliYunOSSService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 包名称：com.example.petproject.service.impl
 * 类名称：CategoryServiceImpl
 * 类描述：商品分类类别实现
 * 创建人：@author DrinkMore-HotWater
 * 创建时间：2024年01月05日 10:31
 **/
@Service
public class PmsProductCategoryServiceImpl implements PmsProductCategoryService {

    @Resource
    private PmsProductCategoryMapper pmsProductCategoryMapper;

    @Resource
    private AliYunOSSService aliYunOSSService;

    /**
     * 查询商品类别
     *
     * @return 商品列表集合
     */
    @Override
    public List<CategoryListVO> getCategoryList() {
        List<CategoryListVO> categoryListVos = pmsProductCategoryMapper.selectCategoryList();
        categoryListVos.forEach(categoryListVO -> {
            categoryListVO.setIcon(aliYunOSSService.getSymink(categoryListVO.getIcon()));
            categoryListVO.getSecProductCategoryList().forEach(
                    item->item.setSecIcon(aliYunOSSService.getSymink(item.getSecIcon()))
            );
        });
        return categoryListVos;
    }
}
